package com.tecsup.oper.servlet.Pronostico;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tecsup.oper.dao.PronosticoBuscarDAO;
import com.tecsup.oper.modelo.Pronostico;

import excepcion.DAOExcepcion;


/**
 * Servlet implementation class PronosticoPronosticoServlet
 */
@WebServlet("/PronosticoPronosticoServlet")
public class PronosticoPronosticoServlet extends javax.servlet.http.HttpServlet implements
javax.servlet.Servlet {
	 static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PronosticoPronosticoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		String a1=request.getParameter("idPronostico");
		Integer no=Integer.parseInt(a1);
		String a = request.getParameter("nombre");

		String b = request.getParameter("pronostico");
		Integer p =Integer.parseInt(b);
		
		String c = request.getParameter("periodo");
			Pronostico vo = new Pronostico();
			vo.setIdPronostico(no);
			vo.setNombre(a);
			vo.setPronostico(p);
			vo.setPeriodo(c);
			
			PronosticoBuscarDAO dao = new PronosticoBuscarDAO();
			
			try {
				dao.actualizar(vo);
				response.sendRedirect(request.getContextPath()+ "/PronosticoBuscarServlet");
			} catch (DAOExcepcion e) {
				System.out.println(e.getMessage());
				RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
				rd.forward(request, response);
			}
	
	}

}
